import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
x="苹果XR"
y="7999"
testCase = "DBshop011商品管理管理商品添加商品"

firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,'商品管理','管理商品')

s=firefox.find_element_by_xpath("//body").text
l="商品数："
r="\)"
order_State=reGetString(s,l,r)
print(order_State)
time.sleep(2)
firefox.find_element_by_partial_link_text('添加商品').click()
firefox.find_element_by_id("goods_name").send_keys(x)
firefox.find_element_by_id("goods_shop_price").send_keys(y)
time.sleep(3)
K = firefox.find_element_by_id("goods_type")
ActionChains(firefox).move_to_element(K).perform()
Select(K).select_by_visible_text("虚拟商品")
time.sleep(3)
firefox.find_element_by_xpath("/html/body/div[2]/div/div[2]/div/form/div/div[1]/div[2]/button").click()
time.sleep(3)
# 断言
x=firefox.find_element_by_xpath("//body").text
l="商品数："
r="\)"
hh=reGetString(x,l,r)
print(hh) #order_State 是实际值
yu=int(hh)-1  #这是预期值
#检查点
if yu==order_State:
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
firefox.quit()